package com.hzcx.app.simplechat.util;

import com.hzcx.app.simplechat.ui.friend.bean.FriendCityBean;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;
import com.hzcx.app.simplechat.util.log.LogUtils;

import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collector;

/**
 * 拼音操作相关工具类
 */
public class PinyinUtil {

    public static String[] pinyins = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T"
            , "U", "V", "W", "X", "Y", "Z"};


    /**
     * 判断字符是否是拼音
     *
     * @param s
     * @return
     */
    public static String isPinyin(char s) {
        if (s >= 65 && s <= 90) {
            return String.valueOf(s);
        }
        if (s >= 97 && s <= 122) {
            return String.valueOf(s);
        }
        return "#";
    }


    /**
     * 根据拼音进行排序
     *
     * @param list
     */
    public static void transferList(List<FriendCityBean> list) {
        Collections.sort(list, (friendCityBean, t1) -> {
            String pinyin1 = friendCityBean.getPinyin().trim().toUpperCase();
            String pinyin2 = t1.getPinyin().trim().toUpperCase();
            Collator ca = Collator.getInstance(Locale.CHINA);
            int flag = 0;
            if (ca.compare(pinyin1, pinyin2) < 0) {
                flag = -1;
                if (isPinyin(pinyin1.charAt(0)).equals("#")) {
                    flag = 1;
                }
                if (isPinyin(pinyin2.charAt(0)).equals("#")) {
                    flag = -1;
                }
            } else if (ca.compare(pinyin1, pinyin2) > 0) {
                flag = 1;
                if (isPinyin(pinyin1.charAt(0)).equals("#")) {
                    flag = 1;
                }
                if (isPinyin(pinyin2.charAt(0)).equals("#")) {
                    flag = -1;
                }
            } else {
                flag = 0;
                if (isPinyin(pinyin1.charAt(0)).equals("#")) {
                    flag = 1;
                }
                if (isPinyin(pinyin2.charAt(0)).equals("#")) {
                    flag = -1;
                }
            }
            return flag;
        });
    }
}
